describe("首页", () => {
  beforeEach(() => {
    const username = "admin";
    const password = "123456";
    cy.login(username, password);
    cy.visit("/");
    cy.getByData("sidebar-menu").contains("安保机器人").click();
    cy.get('[href="/inspection/control-home"] > .el-menu-item').click();
  });

  it("进入操控端", () => {
    // 断言操控端首页初始状态是否正常
    cy.contains("室外").should("have.class", "is-active");
    cy.contains("巡检任务").should("have.class", "is-active");
  });

  it("切换室内/室外机器人", () => {
    cy.get("#tab-inspection").click();
    // 断言室内机器人选项是否选中
    cy.contains("室内").should("have.class", "is-active");
    cy.get("#tab-outsideInspection").click();
    // 断言室外机器人选项是否选中
    cy.contains("室外").should("have.class", "is-active");
  });

  it("位置校准", () => {
    cy.getByData("inspection-robot-item").rightclick();
    cy.contains("位置校准").click();
    cy.get(".el-input__wrapper").click();

    // 选择地图
    cy.get(
      ".el-select-dropdown__wrap > .el-scrollbar__view > :nth-child(1)"
    ).click();
    cy.wait(1000);

    // Todo：缩放测试
    // cy.get("#mapDialogKonva > .konvajs-content > canvas").trigger(
    //   "wheel",
    //   "center",
    //   {
    //     deltaY: 200,
    //   }
    // );

    // 点击坐标点
    cy.get("#mapDialogKonva").click(100, 100).wait(500);
    cy.get("#mapDialogKonva").click(200, 200).wait(500);

    // 确定
    cy.contains("确定").click().wait(1000);
    cy.get(".el-message-box__btns > .el-button--primary").click();

    cy.contains("操作成功").should("exist");
  });

  it("查看机器人状态", () => {
    // 命名接口
    cy.intercept(
      { method: "GET", url: "/api/robot-inspection-log/v1/faultInfo/*" },
      {
        statusCode: 200,
        body: {
          code: 200,
          message: "操作成功",
          data: {
            code: "OI202210264243",
            controlBoxCode: 0,
            flameSensorCode: 0,
            tempCode: 0,
            humidCode: 0,
            noiseCode: 0,
            pm10Code: 0,
            pm25Code: 0,
            hitSensorCode: 0,
            radarCode: 0,
            mileage: 0,
            navStatus: 4,
            wheelStatus: 1,
          },
        },
        headers: { "access-control-allow-origin": "*" },
      }
    ).as("getRobotInspectionLog");
    // 打开机器人状态弹窗
    cy.getByData("inspection-robot-item").rightclick();
    cy.contains("机器人状态").click();
    // 判断接口返回数据
    cy.wait("@getRobotInspectionLog");
    cy.contains("运动系统状态").next("td").contains("正常").should("exist");
  });

  it("进入操控端", () => {
    cy.getByData("inspection-robot-item").rightclick();
    cy.contains("进入操控端").click();
    cy.wait(1000);
    // 判断是否进入到操控端页面
    cy.url().should("contain", "/inspection/control");
  });
});
